/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nus.dataaccess.dao.author;

import com.nus.constant.ConstantAuthorType;
import com.nus.dataaccess.dao.base.BaseEntity;
import com.nus.dataaccess.dao.conference.ConferenceAuthor;
import com.nus.dataaccess.dao.user.UserAccount;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 *
 * @author robin.foe
 */

@Entity
@Table(name="AUTHOR")
public class Author extends BaseEntity{
    
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    public Long getId() {return id;}
    public void setId(Long id) {this.id = id;}
    @Override
    public Serializable getPk() {return this.getId();}
    
    @Column(name="TYPE")
    private String type = ConstantAuthorType.MEMBER;
    public String getType() {return type;}
    public void setType(String type) {this.type = type;}
    
    @Column(name="CONFERENCE_AUTHOR_ID")
    private Long conferenceAuthorId;
    public Long getConferenceAuthorId() {return conferenceAuthorId;}
    public void setConferenceAuthorId(Long conferenceAuthorId) {this.conferenceAuthorId = conferenceAuthorId;}
    
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="CONFERENCE_AUTHOR_ID", referencedColumnName="ID",insertable=false,updatable=false)
    private ConferenceAuthor conferenceAuthor;
    public ConferenceAuthor getConferenceAuthor() {return conferenceAuthor;}
    public void setConferenceAuthor(ConferenceAuthor conferenceAuthor) {
        this.conferenceAuthor = conferenceAuthor;
        this.setConferenceAuthorId((conferenceAuthor == null) ? null : conferenceAuthor.getId());
    }
    
    @Column(name="USER_ACCOUNT_ID")
    private Long userAccountId;
    public Long getUserAccountId() {return userAccountId;}
    public void setUserAccountId(Long userAccountId) {this.userAccountId = userAccountId;}
    
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="USER_ACCOUNT_ID", referencedColumnName="ID",insertable=false,updatable=false)
    private UserAccount userAccount;
    public UserAccount getUserAccount() {return userAccount;}
    public void setUserAccount(UserAccount userAccount) {
        this.userAccount = userAccount;
        this.setUserAccountId( (userAccount == null) ? null : userAccount.getId() );
    }
    
    
    /*******************UTILITY***********************/
    public boolean isUploader(){return ConstantAuthorType.UPLOADER.equals(this.getType());}
    
}
